export function getStorage(keyName) {
    return sessionStorage.getItem(keyName)
}

export function setStorage(keyName, keyVal) {
    return sessionStorage.setItem(keyName, keyVal)
}

export function removeStorage(keyName) {
    return sessionStorage.removeItem(keyName)
}

//获取cookie
export function getCookie(name) {
    let arr = []
    let reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    arr = document.cookie.match(reg)
    if (arr) {
        return (arr[2]);
    } else {
        return null
    }

}

//设置cookie
export function setCookie(c_name, value, expiredays) {
    let days = expiredays || 30;
    let exdate = new Date();

    exdate.setTime(exdate.getTime() + days * 24 * 60 * 60 * 1000);
    document.cookie = c_name + "=" + escape(value) + ";expires=" + exdate.toGMTString();

    // exdate.setDate(exdate.getDate() + expiredays);
    // document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}

//删除cookie
export function delCookie(name) {
    let exp = new Date();
    exp.setTime(exp.getTime() - 1);
    let cval = getCookie(name);
    if (cval != null)
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}